﻿Imports System.Data.OleDb
Public Class newitem
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btn_submit_Click(sender As Object, e As EventArgs) Handles btn_submit.Click
        Dim myGUID As New System.Guid
        myGUID = Guid.NewGuid()
        Dim NewFileName = myGUID.ToString() + ".jpg"

        If fu_Picture.HasFile Then
            Dim fileLocationOnServerHardDisk = Request.MapPath("pictures") & "/" & NewFileName
            fu_Picture.SaveAs(fileLocationOnServerHardDisk)
        End If

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("HeroesConnectionString").ConnectionString)
        Dim SqlString As String = "Insert into MoreDetails(HeroName,AlterEgo,SuperHeroAbilities,AlterEgoAbilities,BackgroundStory,FirstAppearance,Picture) Values (@f1,@f2,@f3,@f4,@f5,@f6,@f7)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", tb_HeroName.Text)
        cmd.Parameters.AddWithValue("@f2", tb_AlterEgo.Text)
        cmd.Parameters.AddWithValue("@f3", tb_HeroAbilities.Text)
        cmd.Parameters.AddWithValue("@f4", tb_AlterEgoAbilities.Text)
        cmd.Parameters.AddWithValue("@f5", tb_BackgroundStory.Text)
        cmd.Parameters.AddWithValue("@f6", tb_FirstAppearance.Text)
        cmd.Parameters.AddWithValue("@f7", "Pictures/" & NewFileName)
        oleDbConn.Open()
        cmd.ExecuteNonQuery()
        Response.Redirect("confirmation.aspx")
    End Sub
End Class